<template>
    <section class="chart-container">
        <el-row>
<!--            <el-col :span="12">-->
<!--                <div id="chartColumn" style="width:100%; height:400px;"></div>-->
<!--            </el-col>-->
<!--            <el-col :span="12">-->
<!--                <div id="chartBar" style="width:100%; height:400px;"></div>-->
<!--            </el-col>-->
            <el-col :span="12">
                <div id="chartLine" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="chartPie" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="24">
                <a href="http://echarts.baidu.com/examples.html" target="_blank" style="float: right;">more>></a>
            </el-col>
        </el-row>
    </section>
</template>

<script>
    import echarts from 'echarts'

    export default {
        data() {
            return {
              chartColumn: null,
              chartBar: null,
              // chartLine: {
              //   times:'',
              //   nums:''
              // },
              chartLine: null,
              chartPie: null
            }
        },

        methods: {
            // drawColumnChart() {
            //     this.chartColumn = echarts.init(document.getElementById('chartColumn'));
            //     this.chartColumn.setOption({
            //       title: { text: 'Column Chart' },
            //       tooltip: {},
            //       xAxis: {
            //           data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
            //       },
            //       yAxis: {},
            //       series: [{
            //           name: '销量',
            //           type: 'bar',
            //           data: [5, 20, 36, 10, 10, 20]
            //         }]
            //     });
            // },
            // drawBarChart() {
            //     this.chartBar = echarts.init(document.getElementById('chartBar'));
            //     this.chartBar.setOption({
            //         title: {
            //             text: 'Bar Chart',
            //             subtext: '数据来自网络'
            //         },
            //         tooltip: {
            //             trigger: 'axis',
            //             axisPointer: {
            //                 type: 'shadow'
            //             }
            //         },
            //         legend: {
            //             data: ['2011年', '2012年']
            //         },
            //         grid: {
            //             left: '3%',
            //             right: '4%',
            //             bottom: '3%',
            //             containLabel: true
            //         },
            //         xAxis: {
            //             type: 'value',
            //             boundaryGap: [0, 0.01]
            //         },
            //         yAxis: {
            //             type: 'category',
            //             data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
            //         },
            //         series: [
            //             {
            //                 name: '2011年',
            //                 type: 'bar',
            //                 data: [18203, 23489, 29034, 104970, 131744, 630230]
            //             },
            //             {
            //                 name: '2012年',
            //                 type: 'bar',
            //                 data: [19325, 23438, 31000, 121594, 134141, 681807]
            //             }
            //         ]
            //     });
            // },
            drawLineChart() {
              this.$http.post("/dept/chartLine").then(res=>{
                // 请求数据，并分别取出需要的值
                let arr = res.data.data;
                let names = arr.map(item => item.name);
                let nums = arr.map(item => item.value);
                // 赋值
                this.chartLine = echarts.init(document.getElementById('chartLine'));
                this.chartLine.setOption({
                  title: {
                      text: '店铺入驻信息'
                  },
                  tooltip: {
                      trigger: 'axis'
                  },
                  legend: {
                      data: ['部门下员工数']
                  },
                  grid: {
                      left: '3%',
                      right: '4%',
                      bottom: '3%',
                      containLabel: true
                  },
                  // 保存
                  toolbox: {
                    feature: {
                      saveAsImage: {}
                    }
                  },
                  xAxis: {
                      type: 'category',
                      boundaryGap: false,
                      data: names
                  },
                  yAxis: {
                      type: 'value'
                  },
                  series: [
                      {
                    name: '各部门员工数',
                    type: 'line',
                    stack: '总量',
                    data: nums
                      },
                  ]
                });
              })
            },
            drawPieChart() {
              this.$http.post("/dept/chartLine").then(res=>{
                // 请求数据，并分别取出需要的值
                let arr = res.data.data;
                let names = arr.map(item => item.name);
                let nums = arr.map(item => item.value);
                // 赋值
                this.chartPie = echarts.init(document.getElementById('chartPie'));
                this.chartPie.setOption({
                    title: {
                        text: '各部门下员工数量统计',
                        subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: names
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            data: arr,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
              })
            },
            drawCharts() {
                //this.drawColumnChart()
                //this.drawBarChart()
                this.drawLineChart()
                this.drawPieChart()
            },
            getLineChartData(){
              this.$http.post("/dept/chartLine").then(res=>{
                var data = res.data.data;
                this.chartLine.times = data.map(item => item.time);
                this.chartLine.nums = data.map(item => item.num);
              })
            },
        },

        mounted: function () {
            this.drawCharts()
            //this.getLineChartData()
        },
        updated: function () {
            this.drawCharts()
        }
    }
</script>

<style scoped>
    .chart-container {
        width: 100%;
        float: left;
    }
    /*.chart div {
        height: 400px;
        float: left;
    }*/

    .el-col {
        padding: 30px 20px;
    }
</style>
